// 导入实例store 的方法
import { defineStore } from 'pinia'

export const useAuthStore = defineStore(
  'auth',
  () => {
    const token = ref('') // 定义 state
    const setToken = (_token: string) => {
      // 定义了一个action方法
      token.value = _token
    }

    // userinfo
    const userInfo = ref()
    const setUserInfo = (res: any) => {
      userInfo.value = res
    }

    // 动态菜单
    const dynamicMenu = ref()
    const setDynamicMenu = (_menu: any) => {
      dynamicMenu.value = _menu
    }

    // 按钮权限
    const auth = ref()
    const allAuth = ref()
    const setAuth = (_auth: any) => {
      auth.value = _auth
    }
    const setAllAuth = (_allAuth: any) => {
      allAuth.value = _allAuth
    }

    return {
      token,
      setToken,
      userInfo,
      setUserInfo,
      dynamicMenu,
      setDynamicMenu,
      auth,
      allAuth,
      setAuth,
      setAllAuth
    }
  },
  {
    persist: true // 持久化
  }
)
